package cn.fl.project.service.impl;

import cmm.comm.facade.framework.api.ISysCtrlCfgApiService;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.api.ISysRegionApiService;
import cmm.comm.facade.framework.condition.SysCtrlCfgQueryCondition;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.framework.dto.SysRegionDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.dk.web.transform.KeyValueVOTransform;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.constant.PrjSplBankAccRConstant;
import cn.fl.project.dto.PrjPrdBscInfoDTO;
import cn.fl.project.service.IProjectApiService;
import cn.fl.project.service.IVehicleStyleService;
import cn.fl.project.transform.PrjPrdBscInfoVOTransform;
import cn.fl.project.transform.PrjPrdParamConfigVOTransform;
import cn.fl.project.transform.VehicleStyleVOTransform;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import cn.fl.project.vo.PrjPrdParamConfigVO;
import cn.fl.project.vo.PrjPrdSourceInfoVO;
import cn.fl.project.vo.VehicleStyleVO;
import com.alibaba.fastjson.JSON;
import cvm.store.facade.cvm.api.IVechileGroupApiService;
import cvm.store.facade.cvm.api.IVechileMakeApiService;
import cvm.store.facade.cvm.api.IVechileParaConfApiService;
import cvm.store.facade.cvm.api.IVechileStyleApiService;
import cvm.store.facade.cvm.condition.VechileGroupQC;
import cvm.store.facade.cvm.condition.VechileMakeQC;
import cvm.store.facade.cvm.condition.VechileStyleQC;
import cvm.store.facade.cvm.dto.VechileGroupDTO;
import cvm.store.facade.cvm.dto.VechileMakeDTO;
import cvm.store.facade.cvm.dto.VechileParaConfDTO;
import cvm.store.facade.cvm.dto.VechileStyleDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 作者:hongyanbo
 * 时间:2018/7/10
 */
@Service
public class VehicleStyleServiceImpl implements IVehicleStyleService {
    private static final Logger logger = LoggerFactory.getLogger(VehicleStyleServiceImpl.class);

    /**
     * 车型库车型参配
     */
    @Autowired
    IVechileParaConfApiService vechileParaConfApiService;
    /**
     * 车型查询
     */
    @Autowired
    IVechileStyleApiService styleApiService;
    /**
     * 品牌 车系 车型接口
     */
    @Autowired
    private IVechileMakeApiService vechileMakeApiService ;
    @Autowired
    private IVechileGroupApiService vechileGroupApiService;
    /**
     * 数据字典
     */
    @Autowired
    private ISysDictionaryApiService dictionaryApiService;
    @Autowired
    private IProjectApiService projectApiService;
    @Autowired
    private ISysCtrlCfgApiService sysCtrlCfgApiService;
    @Autowired
    private ISysRegionApiService sysRegionApiService;

    @Override
    public List<KeyValueVO> getBrandList() {
        List<KeyValueVO> res = new ArrayList<>();
        VechileMakeQC qc = new VechileMakeQC();
        qc.setSysCh("CHL0001");
        qc.setSysCd("11000");
        List<VechileMakeDTO> vechileMakeDTOS = vechileMakeApiService.selectMakeList(qc);
        res = transfer2VO( qc, vechileMakeDTOS);
        return res;
    }

    @Override
    public List<KeyValueVO> getModelList(Long brandId) {
        List<KeyValueVO> res = new ArrayList<>();
        VechileMakeQC qc = new VechileMakeQC();
        qc.setSysCh("CHL0001");
        qc.setSysCd("11000");
        qc.setMakeid(brandId);
        List<VechileMakeDTO> vechileMakeDTOS = vechileMakeApiService.selectModelList(qc);
        if(CollectionUtils.isNotEmpty(vechileMakeDTOS)){
            for (VechileMakeDTO vechileMakeDTO : vechileMakeDTOS) {
                KeyValueVO vo = new KeyValueVO();
                vo.setKey(String.valueOf(vechileMakeDTO.getModelid()));
                vo.setValue(vechileMakeDTO.getModelname());
                res.add(vo);
            }
        }else{
            BaseLogUtils.info(logger,"getBrandList","查询品牌失败，返回空condition:"+ JSON.toJSONString(qc));
            return null;
        }
        return res;
    }

    @Override
    public List<KeyValueVO> getStyleList(Long makeId, Long carModelId, Long purpose) {
        List<KeyValueVO> res = new ArrayList<>();
        VechileMakeQC qc = new VechileMakeQC();
        qc.setSysCh("CHL0001");
        qc.setSysCd("11000");
//        qc.setMakeid(makeId);
        qc.setModelid(carModelId);
        qc.setStylePurposeId(purpose);
        BaseLogUtils.info(logger,"调用vechileMakeApiService.getStyleList 参数：",JSON.toJSONString(qc));
        List<VechileMakeDTO> vechileMakeDTOS = vechileMakeApiService.selectStylelList(qc);
        BaseLogUtils.info(logger,"调用vechileMakeApiService.getStyleList返回结果","结果数量："+vechileMakeDTOS.size());
        if(CollectionUtils.isNotEmpty(vechileMakeDTOS)){
            for (VechileMakeDTO vechileMakeDTO : vechileMakeDTOS) {
                KeyValueVO vo = new KeyValueVO();
                vo.setKey(String.valueOf(vechileMakeDTO.getStyleId()));
                vo.setValue(vechileMakeDTO.getStyleName());
                res.add(vo);
            }
        }else{
            BaseLogUtils.info(logger,"getBrandList","查询品牌失败，返回空condition:"+ JSON.toJSONString(qc));
            return null;
        }
        return res;
    }

    @Override
    public List<KeyValueVO> getCarUsageDicList(int lvl, String pcode) {
        List<KeyValueVO> res = new ArrayList<>();
        List<SysDictionaryDTO> carUsage = dictionaryApiService.searchGroupWithLevel("15000", "0000", "CVM0001", lvl);
        if(CollectionUtils.isNotEmpty(carUsage)){
            for (SysDictionaryDTO sysDictionaryDTO : carUsage) {
                KeyValueVO vo = new KeyValueVO();
                vo.setKey(sysDictionaryDTO.getCode());
                vo.setValue(sysDictionaryDTO.getCodeNm());
                if(StringUtils.isNotBlank(pcode)){
                    if(sysDictionaryDTO.getPCode().equals(pcode)){
                        res.add(vo);
                    }
                }else{
                    res.add(vo);
                }
            }
        }
        return res;
    }

    @Override
    public Pager selectListPage(Pager page) {
        VechileStyleQC condition = (VechileStyleQC) page.getCondition();
        condition.setStyleStatus(1L); //车型状态为启用的
        String styleBulletinModel = condition.getStyleBulletinModel();
        // 如果填写公告型号，其他条件就都不使用了
        if(StringUtils.isNotBlank(styleBulletinModel)){
            condition.setStyleBulletinModel(styleBulletinModel);
        }
        // 如果选择了车系就不传品牌
          Long modelid = condition.getModelid();
        if(modelid!=null){
            condition.setMakeId(null);
        }
        // 如果选择了车型就不传车系
        Long styleId = condition.getStyleId();
        if(styleId!=null){
            condition.setModelid(null);
        }
        Pager pager = styleApiService.searchListPage(page);
        // 转码
        if(pager!=null){
            List<VechileStyleDTO> resultList = (List<VechileStyleDTO>) pager.getResultList();
            if(CollectionUtils.isNotEmpty(resultList)){
                // 驱动形式
                for (VechileStyleDTO dto : resultList) {
                    if(StringUtils.isNotBlank(dto.getStyleDriveMode())){
                        SysDictionaryDTO cvm0003 = this.dictionaryApiService.getCode("15000", "0000", "CVM0003", dto.getStyleDriveMode());
                        if(cvm0003!=null){
                            dto.setStyleDriveMode(cvm0003.getCodeNm());
                        }
                    }
                }
            }
        }
        return pager;
    }

    @Override
    public PrjPrdParamConfigVO getPrdDetail(Long id) {
        // 查询车型库参配信息
        List<VechileParaConfDTO> vechileParaConfDTOS = vechileParaConfApiService.searchByStyleId(id);
        BaseLogUtils.info(logger,"getPrdDetail","styleAAA:"+ JSON.toJSONString(vechileParaConfDTOS));
        if(CollectionUtils.isNotEmpty(vechileParaConfDTOS)){
            PrjPrdParamConfigVO prjPrdParamConfigVO = PrjPrdParamConfigVOTransform.voAdapter(vechileParaConfDTOS);
            // 查询车型库信息
            VechileStyleDTO vechileStyleDTO = styleApiService.selectById(id);
            BaseLogUtils.newLogger("getPrdDetail 通过车型ID获取车辆信息 车型ID={},车辆信息={}"
                    ,id,JSON.toJSONString(vechileStyleDTO)).info();
            if (vechileStyleDTO != null) {
                if (vechileStyleDTO.getStyleMsrp() != null) {
                    prjPrdParamConfigVO.setMfrGuidePc(String.valueOf(vechileStyleDTO.getStyleMsrp() * 10000));
                }
            }
            // 驱动形式转码
            String drvTypCd = prjPrdParamConfigVO.getDrvTypCd();
            if(StringUtils.isNotBlank(drvTypCd)){
                SysDictionaryDTO cvm0003 = this.dictionaryApiService.getCode("15000", "0000", "CVM0003", drvTypCd);
                prjPrdParamConfigVO.setDrvTypCd(cvm0003.getCodeNm());
            }
            // 用途转码
            String prdNm = prjPrdParamConfigVO.getPrdNm();
            if(StringUtils.isNotBlank(prdNm)){
                SysDictionaryDTO purposeDictionaryDTO = getPurposeDictionaryDTO(prdNm);
                if(purposeDictionaryDTO != null){
                    prjPrdParamConfigVO.setPrdNm(purposeDictionaryDTO.getCodeNm());
                }
            }
            String prdTypCdNm = prjPrdParamConfigVO.getPrdTypCdNm();
            if(StringUtils.isNotBlank(prdTypCdNm)){
                SysDictionaryDTO purposeDictionaryDTO = getPurposeDictionaryDTO(prdTypCdNm);
                if(purposeDictionaryDTO !=null){
                    prjPrdParamConfigVO.setPrdTypCdNm(purposeDictionaryDTO.getCodeNm());
                }
            }
            // 燃料类型转码
            String fuelTypCd = prjPrdParamConfigVO.getFuelTypCd();
            if(StringUtils.isNotBlank(fuelTypCd)){
                SysDictionaryDTO cvm0004 = this.dictionaryApiService.getCode("15000", "0000", "CVM0004", fuelTypCd);
                if(cvm0004!=null){
                    prjPrdParamConfigVO.setFuelTypCd(cvm0004.getCodeNm());
                }
            }
            // 排放标准 CVM0006
            String emiStd = prjPrdParamConfigVO.getEmiStd();
            if(StringUtils.isNotBlank(emiStd)){
                SysDictionaryDTO cvm0006 = this.dictionaryApiService.getCode("15000", "0000", "CVM0006", emiStd);
                prjPrdParamConfigVO.setEmiStd(cvm0006.getCodeNm());
                prjPrdParamConfigVO.setEmiStdCd(cvm0006.getCodeNm());
            }
            // 动力方式转码 powerTypCd
            String powerTypCd = prjPrdParamConfigVO.getPowerTypCd();
            if(StringUtils.isNotBlank(powerTypCd)){
                SysDictionaryDTO cvm0004 = this.dictionaryApiService.getCode("15000", "0000", "CVM0004", powerTypCd);
                if(cvm0004!=null){
                    prjPrdParamConfigVO.setPowerTypCd(cvm0004.getCodeNm());
                }
            }
            if(StringUtils.isNotBlank(prjPrdParamConfigVO.getGuidePc())){
                String val = String.valueOf(Double.valueOf(prjPrdParamConfigVO.getGuidePc())/100);
                BaseLogUtils.info(logger,"getPrdDetail","guidePc:"+ JSON.toJSONString(val));
                prjPrdParamConfigVO.setGuidePc(val);
            }
            return prjPrdParamConfigVO;
        }else{
            BaseLogUtils.error(logger,"getPrdDetail","车型库，车型信息查询失败");
            throw new BaseException("车型库，车型信息查询失败" + id);
        }
    }

    @Override
    public String getPurposePCd(Long purposeCd) {
        SysDictionaryDTO pCd = getPurposeDictionaryDTO(String.valueOf(purposeCd));
        if(pCd!=null){
            return pCd.getPCode();
        }
        return null;
    }

    @Override
    public SysDictionaryDTO getPurposeDictionaryDTO(String purposeCd) {
        return dictionaryApiService.getCode("15000", "0000", "CVM0001", purposeCd);
    }

    @Override
        public PrjPrdBscInfoVO getPrjPrdBscnInfoAndExtById(String id) {
        if(StringUtils.isBlank(id)){
            BaseLogUtils.info(logger, "getPrjPrdBscnInfoAndExtById", "id不能为空！", CurrentThreadContext.getCurrentUserName());
        }
        PrjPrdBscInfoDTO prjPrdBscInfoDTO = this.projectApiService.selectPrjPrdBscInfoAndExtById(id,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
        PrjPrdBscInfoVO prjPrdBscInfo = PrjPrdBscInfoVOTransform.toVO(prjPrdBscInfoDTO);
        String orgCd = CurrentThreadContext.getCurrentOrgCd();
        SysCtrlCfgQueryCondition qc = new SysCtrlCfgQueryCondition();
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        if(orgCd.length()>8){
            if(orgCd.substring(0, 8).equals("00000008")){
                qc.setCtrlCode(DictionaryConstant.CTRL_PRJ_PRD_COUNT_ZK);
            }else{
                qc.setCtrlCode(DictionaryConstant.CTRL_PRJ_PRD_COUNT);
            }
        }else{
            qc.setCtrlCode(DictionaryConstant.CTRL_PRJ_PRD_COUNT);
        }
        String ctrValue=sysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(qc);
        prjPrdBscInfo.setCtrValue(ctrValue);
        if(null!=prjPrdBscInfo.getInvAmt()){
            prjPrdBscInfo.setInvAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getInvAmt().longValue()));
        }

        if(null!=prjPrdBscInfo.getGuidePc()){
            prjPrdBscInfo.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getGuidePc().longValue()));
        }
        if(null!=prjPrdBscInfo.getPrdAmt()){
            prjPrdBscInfo.setPrdAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getPrdAmt().longValue()));
        }
        if(null!=prjPrdBscInfo.getRsrvPc()){
            prjPrdBscInfo.setRsrvPc(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getRsrvPc().longValue()));
        }
        if(null!=prjPrdBscInfo.getVehVal()){
            prjPrdBscInfo.setVehVal(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getVehVal().longValue()));
        }
        if(null!=prjPrdBscInfo.getCustFina()){
            prjPrdBscInfo.setCustFina(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getCustFina().longValue()));
        }
        if(null!=prjPrdBscInfo.getLoanableAmt()){
            prjPrdBscInfo.setLoanableAmt(DecimalUtils.convertFenToYuan(prjPrdBscInfo.getLoanableAmt().longValue()));
        }
        if(null!=prjPrdBscInfo.getPrjPrdSourceInfo()){
            PrjPrdSourceInfoVO sourceInfoDTO = prjPrdBscInfo.getPrjPrdSourceInfo();
            if(null!=sourceInfoDTO.getEstRetailminprice()){
                sourceInfoDTO.setEstRetailminprice(DecimalUtils.convertFenToYuan(sourceInfoDTO.getEstRetailminprice().longValue()));
            }
            if(null!=sourceInfoDTO.getEstRetailmaxprice()){
                sourceInfoDTO.setEstRetailmaxprice(DecimalUtils.convertFenToYuan(sourceInfoDTO.getEstRetailmaxprice().longValue()));
            }
            if(null!=sourceInfoDTO.getEstPurminprice()){
                sourceInfoDTO.setEstPurminprice(DecimalUtils.convertFenToYuan(sourceInfoDTO.getEstPurminprice().longValue()));
            }
            if(null!=sourceInfoDTO.getEstPurmaxprice()){
                sourceInfoDTO.setEstPurmaxprice(DecimalUtils.convertFenToYuan(sourceInfoDTO.getEstPurmaxprice().longValue()));
            }
            if(null!=sourceInfoDTO.getPurchasingPrice()){
                sourceInfoDTO.setPurchasingPrice(DecimalUtils.convertFenToYuan(sourceInfoDTO.getPurchasingPrice().longValue()));
            }
            if(null!=sourceInfoDTO.getEvaOfPrice()){
                sourceInfoDTO.setEvaOfPrice(DecimalUtils.convertFenToYuan(sourceInfoDTO.getEvaOfPrice().longValue()));
            }
            if(null!=sourceInfoDTO.getVehValNew()){
                sourceInfoDTO.setVehValNew(DecimalUtils.convertFenToYuan(sourceInfoDTO.getVehValNew().longValue()));
            }
            //省市
            if(null!=sourceInfoDTO.getProvCd()){
                SysRegionDTO prRegion = this.sysRegionApiService.getRegionByRgnCd(sourceInfoDTO.getProvCd(), CurrentThreadContext.getFlServiceSysCd());
                if(null!=prRegion){
                    sourceInfoDTO.setPrvCodeNm(prRegion.getRgnNm());
                }
            }
            if(null!=sourceInfoDTO.getCityCd()){
                SysRegionDTO cyRegion = this.sysRegionApiService.getRegionByRgnCd(sourceInfoDTO.getCityCd(), CurrentThreadContext.getFlServiceSysCd());
                if(null!=cyRegion){
                    sourceInfoDTO.setCityCodeNm(cyRegion.getRgnNm());
                }
            }
        }
        // 字典
        // 用途字典
        String prdTypCd = prjPrdBscInfo.getPrdTypCd();
        if (StringUtils.isNotBlank(prdTypCd)) {
            SysDictionaryDTO purposeDictionaryDTO = this.getPurposeDictionaryDTO(prdTypCd);
            if(purposeDictionaryDTO!=null){
                prjPrdBscInfo.setPrdTypCdNm(purposeDictionaryDTO.getCodeNm());
            }
        }

       /* //验车方式
        if(StringUtils.isNotBlank(prjPrdBscInfo.getVehCheckCode())){
            if(prjPrdBscInfo.getVehCheckCode().equals("0")){
                prjPrdBscInfo.setVehCheckCodeNm("未验车");
            }
            if(prjPrdBscInfo.getVehCheckCode().equals("1")){
                prjPrdBscInfo.setVehCheckCodeNm("线上验车");
            }
            if(prjPrdBscInfo.getVehCheckCode().equals("2")){
                prjPrdBscInfo.setVehCheckCodeNm("线下验车");
            }
        }*/
        return prjPrdBscInfo;
    }

    @Override
    public List<KeyValueVO> getCarUsageLv1(Long modelId) {
        // 父级代码Map
        Map<String,SysDictionaryDTO> pCodeMap = new HashMap<>();
        List<VechileStyleDTO> vechileStyleDTOS = this.styleApiService.selectTypeByModelId(modelId);
        if(CollectionUtils.isNotEmpty(vechileStyleDTOS)){
            for (VechileStyleDTO vechileStyleDTO : vechileStyleDTOS) {
                SysDictionaryDTO cvm0001 = this.dictionaryApiService.getCode("15000", "0000", "CVM0001", String.valueOf(vechileStyleDTO.getStylePurposeId()));
                if(cvm0001!=null && !pCodeMap.containsKey(cvm0001.getPCode())){
                    pCodeMap.put(cvm0001.getPCode(),cvm0001); //value 没有意义，就是为了去重
                }
            }
        }
        // 查询父code
        // 封装结果
        List<KeyValueVO> res = new ArrayList<>();
        Set<Map.Entry<String, SysDictionaryDTO>> entries = pCodeMap.entrySet();
        for (Map.Entry<String, SysDictionaryDTO> entry : entries) {
            String key = entry.getKey();
            SysDictionaryDTO cvm0001 = this.dictionaryApiService.getCode("15000", "0000", "CVM0001", String.valueOf(key));
            if(cvm0001!=null){
                KeyValueVO vo = new KeyValueVO();
                vo.setKey(cvm0001.getCode());
                vo.setValue(cvm0001.getCodeNm());
                res.add(vo);
            }
        }
        return res;
    }

    @Override
    public List<KeyValueVO> getCarUsageLv2(String modelId, String lv1) {
        List<KeyValueVO> res = new ArrayList<>();
        //查询所有车系下的用途
        List<VechileStyleDTO> vechileStyleDTOS = this.styleApiService.selectTypeByModelId(Long.parseLong(modelId));
        // 过滤分类下的用途
        if(CollectionUtils.isNotEmpty(vechileStyleDTOS)){
            for (VechileStyleDTO vechileStyleDTO : vechileStyleDTOS) {
                KeyValueVO vo = new KeyValueVO();
                vo.setKey(String.valueOf(vechileStyleDTO.getStylePurposeId()));
                vo.setValue(vechileStyleDTO.getStylePurposeName());
                SysDictionaryDTO cvm0001 = this.dictionaryApiService.getCode("15000", "0000", "CVM0001", String.valueOf(vechileStyleDTO.getStylePurposeId()));
                if(StringUtils.isNotBlank(lv1)){
                    if(lv1.equals(cvm0001.getPCode())){
                        res.add(vo);
                    }
                }else{
                    res.add(vo);
                }
            }
        }

        return res;
    }

    @Override
    public List<KeyValueVO> getMfrList() {
        BaseLogUtils.info(logger,"getMfrList","查询挂车厂商");
        VechileGroupQC vechileGroupQC = new VechileGroupQC();
        vechileGroupQC.setSysCd("15000");
        vechileGroupQC.setSysCh("CHL0016");
        List<VechileGroupDTO> vechileGroupDTOS = this.vechileGroupApiService.selectTtailerManu(vechileGroupQC);
        BaseLogUtils.info(logger,"getMfrList","查询挂车厂商结果数量:"+vechileGroupDTOS.size());
        // 封装KEYVALUE
        List<KeyValueVO> res = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(vechileGroupDTOS)){
            for (VechileGroupDTO vechileGroupDTO : vechileGroupDTOS) {
                KeyValueVO vo = new KeyValueVO();
                vo.setKey(String.valueOf(vechileGroupDTO.getId()));
                vo.setValue(vechileGroupDTO.getGroupName());
                res.add(vo);
            }
        }
        return res;
    }

    @Override
    public List<KeyValueVO> getTrailerUsageList() {
        //挂车的子码
        List<SysDictionaryDTO> cvm0001 = this.dictionaryApiService.searchChild("15000", "0000", "CVM0001", "9");
        // KEYVALUEVO
        List<KeyValueVO> res = KeyValueVOTransform.toVoList(cvm0001);
        return res;
    }

    @Override
    public List<KeyValueVO> getReceiveTypeCdList() {
        String code = PrjSplBankAccRConstant.CODE_RECEIVE_TYPE_CD;
        String attr1 = PrjSplBankAccRConstant.CODE_RECEIVE_TYPE_CD_MARK;
        return this.dictionaryApiService.getKvListWithAttr1(code,attr1,CurrentThreadContext.getFlServiceSysCd(),CurrentThreadContext.getCurrentOrgCd());
    }

    @Override
    public Pager selectTrailerListPage(Pager pager) {

        Pager res = styleApiService.searchListPage(pager);
        List<VechileStyleDTO> resultList = (List<VechileStyleDTO>) res.getResultList();
        // DTO 转 VO
        List<VehicleStyleVO> vehicleStyleVOS = VehicleStyleVOTransform.toVOList(resultList);
        // 参配项
        if(CollectionUtils.isNotEmpty(vehicleStyleVOS)){
            for (VehicleStyleVO vehicleStyleVO : vehicleStyleVOS) {
                List<VechileParaConfDTO> vechileParaConfDTOS = this.vechileParaConfApiService.searchByStyleId(vehicleStyleVO.getId());
                    PrjPrdParamConfigVO prjPrdParamConfigVO = PrjPrdParamConfigVOTransform.voAdapter(vechileParaConfDTOS);
                if(prjPrdParamConfigVO != null){
                    vehicleStyleVO.setTankVol(prjPrdParamConfigVO.getTankVol()); //罐体容积
                    vehicleStyleVO.setBridgeNum(prjPrdParamConfigVO.getBridgeNum()); //车桥数量
                    vehicleStyleVO.setBridgeBrand(prjPrdParamConfigVO.getBridgeBrand()); //车桥品牌
                    vehicleStyleVO.setWhlNum(prjPrdParamConfigVO.getWhlNum()); //轮胎数量
                    vehicleStyleVO.setmWhlSpec(prjPrdParamConfigVO.getmWhlSpec()); //轮胎规格
                }

            }
            res.setResultList(vehicleStyleVOS);
        }
        return res;
    }


    private List<KeyValueVO> transfer2VO( VechileMakeQC qc, List<VechileMakeDTO> vechileMakeDTOS) {
        List<KeyValueVO> res = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(vechileMakeDTOS)){
            for (VechileMakeDTO vechileMakeDTO : vechileMakeDTOS) {
                KeyValueVO vo = new KeyValueVO();
                vo.setKey(String.valueOf(vechileMakeDTO.getMakeid()));
                vo.setValue(vechileMakeDTO.getMakename());
                res.add(vo);
            }
        }else{
            BaseLogUtils.info(logger,"getBrandList","查询品牌失败，返回空condition:"+ JSON.toJSONString(qc));
            return null;
        }
        return res;
    }
}
